package com.qf.im.entity.bo;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

@Data
@Accessors(chain = true)
@Document(indexName = "house_index")
@Setting(shards = 1, replicas = 0)
public class HouseEsBo {
    @Id
    private Integer id;
    //房屋标题
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
            otherFields = @InnerField(suffix = "py", type = FieldType.Text, analyzer = "pinyin")
    )
    private String subject;
    //房屋封面
    @Field(type = FieldType.Keyword)
    private String image;
    //1-公寓 2-民房 3-商品房
    @Field(type = FieldType.Integer)
    private Integer type;
    //几室
    @Field(type = FieldType.Integer)
    private Integer shi;
    //几厅
    @Field(type = FieldType.Integer)
    private Integer ting;
    //房租
    @Field(type = FieldType.Double)
    private Double price;
    //详细描述
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
            otherFields = @InnerField(suffix = "py", type = FieldType.Text, analyzer = "pinyin")
    )
    private String info;
    //地址
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String address;
    //纬度
    private Double lat;
    //经度
    private Double lng;

    @GeoPointField
    private GeoPoint location;

    public void setLat(Double lat) {
        this.lat = lat;
        initLocation();
    }

    public void setLng(Double lng) {
        this.lng = lng;
        initLocation();
    }

    /**
     * 初始化地理坐标点
     */
    public void initLocation(){
        if (this.lat != null && this.lng != null){
            location = new GeoPoint(this.lat, this.lng);
        }
    }
}
